﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>业务管理界面</title>
    <link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../demo.css">
    <script type="text/javascript" src="../jquery.min.js"></script>
    <script type="text/javascript" src="../jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../jquery.cookie.js"></script>
    <script type="text/javascript" src="../extend.js"></script>
    <script type="text/javascript">
		var salesPoints = getSalesPoint();
        $(document).ready(function () {
			showMask('请稍后');
            initProfile();
            initModules();
			makeList();
            setInterval(initProfile, 60000);
			setInterval(makeList, 70000);
			hideMask();
        });
        function TabClosing(title, index) {
            var target = this;
            $.messager.confirm('提示', '确定关闭页面[' + title + "]？", function (r) {
                if (r) {
                    var opts = $(target).tabs('options');
                    var bc = opts.onBeforeClose;
                    opts.onBeforeClose = function () { };  // allowed to close now
                    $(target).tabs('close', index);
                    opts.onBeforeClose = bc;  // restore the event function
                }
            });
            return false;	// prevent from closing
        }
        function initProfile() {
            $.get("../../api/user/whoami", function (response) {
                if (response.Result == 0) {
                    var profile = JSON.parse(response.Data);
                    var info = "当前登录身份:" + profile.SiteName + "/" + valToName(salesPoints, profile.SalesPoint) + "/" + profile.UserName;
                    info += " <a href='#' onClick=addTab('0','修改密码','../chgpwd.html')>修改密码>></a> <a href='../logout.html'>注销>></a>";
                    $("#profile").html(info);
                    $.cookie('profile', JSON.stringify(profile));
                } else {
                    $.messager.alert("错误", "登录超时", "error");
                    window.location = "../login.html";
                }
            }, "json")
                .error(function () {
                    $.messager.alert("错误", "系统内部错误", "error");
                    window.location = "../login.html";
                })
        }
        function initModules() {
            $.get("../../api/modules/listmenu", function (response) {
                if (response.Result == 0) {
                    var modules = JSON.parse(response.Data);
                    $("#menu").tree("loadData", modules);
                    for(var i=0;i<modules.length;i++){
                        if(!modules[i].DeskLink){continue;}
                        var html = "<a onClick=addTab('"+modules[i].AutoId+"','"+modules[i].Name+"','"+modules[i].AppUrl+"') class='easyui-linkbutton' style='margin:10px 10px 10px 10px,width:64px' data-options=\"iconCls:'icon-large-picture',size:'large',iconAlign:'top'\">"+modules[i].Name+"</a>&nbsp&nbsp";
                        $("#deskLink").append(html);
                    }
                    $.parser.parse();  
                } else {
                    $.messager.alert("错误", response.Message, "error");
                }
            }, "json")
                .error(function () {
                    $.messager.alert("错误", "系统内部错误", "error");
                })
        }
        function gotoInfo(rowIndex,rowData){
			addTab(rowData.Module,rowData.MsgType,rowData.Url,'&'+rowData.Arg);
		}
		function makeList(){
			var list = [];
			$.ajaxSettings.async=false;
			$.get("../../api/quote/list",{Args:[{'Key':'State','Value':2,'Op':'Eq'}]},
				function(data){
					if(data.Result==0){
						var record = JSON.parse(data.Data);
						for(var i=0;i<record.length;i++){
							list.push({'MsgType':'待审提示','Time':record[i].CreateDate,'Detail':'报价单待审批:'+record[i].Code,'Url':'quote.html','Arg':'autoid='+record[i].AutoId,'Module':16});
						}
					}
				},'json');
			$.get("../../api/order/list",{Args:[{'Key':'State','Value':2,'Op':'Eq'}]},
				function(data){
					if(data.Result==0){
						var record = JSON.parse(data.Data);
						for(var i=0;i<record.length;i++){
							list.push({'MsgType':'待审提示','Time':record[i].CreateDate,'Detail':'订单待审批:'+record[i].OrderCode,'Url':'order.html','Arg':'autoid='+record[i].AutoId,'Module':18});
						}
					}
				},'json');
			$.get("../../api/salesbonus/list",{Args:[{'Key':'State','Value':2,'Op':'Eq'}]},
				function(data){
					if(data.Result==0){
						var record = JSON.parse(data.Data);
						for(var i=0;i<record.length;i++){
							list.push({'MsgType':'待审提示','Time':record[i].CreateDate,'Detail':'销售计提待审批:'+record[i].Code,'Url':'salesbonus.html','Arg':'cusid='+record[i].CustomerId,'Module':19});
						}
					}
				},'json');
			$.get("../../api/designerbonus/list",{Args:[{'Key':'State','Value':2,'Op':'Eq'}]},
				function(data){
					if(data.Result==0){
						var record = JSON.parse(data.Data);
						for(var i=0;i<record.length;i++){
							list.push({'MsgType':'待审提示','Time':record[i].CreateDate,'Detail':'设计返点待审批:'+record[i].Code,'Url':'designerbonus.html','Arg':'cusid='+record[i].CustomerId,'Module':20});
						}
					}
				},'json');
			$.get("../../api/servicebonus/list",{Args:[{'Key':'State','Value':2,'Op':'Eq'}]},
				function(data){
					if(data.Result==0){
						var record = JSON.parse(data.Data);
						for(var i=0;i<record.length;i++){
							list.push({'MsgType':'待审提示','Time':record[i].CreateDate,'Detail':'安装费用待审批:'+record[i].Code,'Url':'servicebonus.html','Arg':'cusid='+record[i].CustomerId,'Module':23});
						}
					}
				},'json');
			$.get("../../api/pay/list",{Args:[{'Key':'State','Value':2,'Op':'Eq'}]},
				function(data){
					if(data.Result==0){
						var record = JSON.parse(data.Data);
						for(var i=0;i<record.length;i++){
							list.push({'MsgType':'待审提示','Time':record[i].CreateDate,'Detail':'收款单待审批:'+record[i].Code,'Url':'pay.html','Arg':'cusid='+record[i].CustomerId,'Module':21});
						}
					}
				},'json');
			$.get("../../api/other/list",{Args:[{'Key':'State','Value':2,'Op':'Eq'}]},
				function(data){
					if(data.Result==0){
						var record = JSON.parse(data.Data);
						for(var i=0;i<record.length;i++){
							list.push({'MsgType':'待审提示','Time':record[i].CreateDate,'Detail':'其他费用待审批:'+record[i].Code,'Url':'other.html','Arg':'autoid='+record[i].AutoId,'Module':25});
						}
					}
				},'json');
			$.ajaxSettings.async=true;
			$('#msgList').datagrid('loadData',list);
		}
    </script>
</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false" style="height:30px;background:#B3DFDA;padding:0px;margin:0px;">
        <!--<img src="../image/logo.png" height="47px"/>-->
        <div style="float:right;padding:5px;color:#0E2D5F"><b id="profile"></b></div>
    </div>
	<div data-options="region:'west',split:true,title:'功能菜单',height:25" style="width:150px;padding:3px;">
		<ul class="easyui-tree" id="menu" data-options="
					animate:true,
					formatter:function(node){
						var s = node.Name;
						return s;
					},
                    onClick:function(node){
                        addTab(node.AutoId,node.Name,node.AppUrl);
                    }
				"></ul>
    </div>
	<div data-options="region:'south',border:false" style="text-align:center;height:25px;background:#A9FACD;padding:0px;margin:0px;font-size:8px">
         <p style="margin-top:3px;margin-bottom:3px">技术支持：李伟权 Tel:13672917587 Email:liweiquande@163.com</p>
    </div>
	<div data-options="region:'center'">
        <div id="mainFrame"  class="easyui-tabs" data-options="
                fit:true,
                border:false,
                tabHeight:25,
            ">
			<div id="mainPage" title="首页" style="padding:20px">
            
			<table id="msgList" class="easyui-datagrid"
					data-options="singleSelect:true,method:'get',onDblClickRow:gotoInfo,striped:true,height:300">
				<thead>
					<tr>
						<th data-options="field:'MsgType',width:150,align:'right'">消息类型</th>
						<th data-options="field:'Time',width:200,align:'right'">消息时间</th>
						<th data-options="field:'Detail',width:600,align:'right'">消息明细</th>
						<th data-options="field:'Url',hidden:true"></th>
						<th data-options="field:'Arg',hidden:true"></th>
						<th data-options="field:'Module',hidden:true"></th>
					</tr>
				</thead>
			</table>
			<div style="margin:20px"></div>
			<div id="deskLink"  style="padding:20px,height:300"></div>
        </div>
    </div>
</body>
</html>